export interface Action<T = any> {
    type: T;
}

//代表任意的action 只要有type属性 其它属性随便给
export interface AnyAction extends Action{
    [extraProps: string]: any;
}

//reducer是一个处理函数,接受老的状态和action动作,返回新的状态
/*export interface Reducer<S = any, A extends Action = AnyAction> {
    (state:S|undefined,action:A):S
}*/
export type Reducer<S = any, A extends Action = AnyAction> = (state: S | undefined, action: A) => S

export type Dispatch<A extends Action = AnyAction> = (action: A) => A //dispatch方法返回值 就是派发的动作action

export type Listener = () => void //监听函数没有参数 也没有返回值

export type Unsubscribe = () => void

export type Subscribe = (listener: Listener) => Unsubscribe

export interface Store<S = any, A extends Action = AnyAction> {
    dispatch: Dispatch<A>; //派发动作 改变仓库中的状态
    getState(): S; //获取当前状态
    subscribe(listener: Listener): Unsubscribe; //订阅仓库中的状态变化事件 传入一个监听函数 返回一个取消订阅的函数
}

/*
S State代表本仓库管理的状态的类型
A Action代表向本仓库派发的动作的类型
*/
/*export interface StoreCreator {
    <S, A extends Action<any> , Ext, StateExt>
    (reducer: Reducer<S, A>, preloadedState?: S): Store<S, A>;
}*/
export type  StoreCreator  = <S, A extends Action<any>, Ext, StateExt> (reducer: Reducer<S, A>, preloadedState?: S) => Store<S, A>

/* interface CombinedState {
counter1: Counter1State
,counter2: Counter2State
}
*/
export type ReducersMapObject<S = any, A extends Action = Action> = {
    [K in keyof S]: Reducer<S[K], A>
};
